home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 261 / SOMC Family Forum 261.iso / Xtras / Behavior Library.cst / 00050_Script_UI Drag Snap to Sprite < prev    next >
Text File  |  1997-11-17  |  2KB  |  64 lines

  1. -- Gesture Snap to Sprite
  2.  
  3.  
  4. -- behavior library version 1.1
  5. property  snapDistance, snapTarget, xoffset, yoffset
  6. property tracking, boxtop, boxleft, boxright,boxbottom
  7.  
  8. on beginsprite  me
  9.   set boxtop    = the locv of sprite snapTarget  - snapDistance
  10.   set boxbottom = the locv of sprite snapTarget  + snapDistance
  11.   set boxleft   = the loch of sprite snapTarget  - snapDistance
  12.   set boxright  = the loch of sprite snapTarget  + snapDistance  
  13.   
  14.   
  15. end
  16.  
  17. on prepareframe me
  18.   if tracking then
  19.     if inbox (me, the mouseH - xoffset, the mouseV - yoffset) then 
  20.       snap me
  21.     else
  22.       set the locH of sprite the spritenum of me = the MouseH - xoffset
  23.       set the locV of sprite the spritenum of me = the MouseV - yoffset
  24.     end if
  25.   end if
  26. end
  27.  
  28. on mousedown me
  29.   set tracking  = TRUE
  30.   set xoffset = the mouseH - the locH of sprite the spritenum of me
  31.   set yoffset = the mouseV - the locV of sprite the spritenum of me
  32.   
  33. end
  34.  
  35. on mouseup me
  36.   set tracking = FALSE
  37. end
  38.  
  39. on snap me
  40.   set the locH of sprite the spritenum of me = the locH of sprite snapTarget 
  41.   set the locV of sprite the spritenum of me = the locV of sprite snapTarget  
  42. end
  43.  
  44.  
  45. on inbox me,x,y
  46.   if x < boxright and x > boxleft and y < boxbottom and y > boxtop then
  47.     return 1
  48.   end if
  49.   return 0
  50. end
  51.  
  52.  
  53. ---
  54.  
  55. on getPropertyDescriptionList
  56.   
  57.   set p_list = [   #snapDistance: [ #comment: "Snap Distance:",                     #format: #integer,                    #default:  8 ],      #snapTarget: [ #comment: "Target Sprite:",                     #format: #integer,                     #default:  1 ]                  ]
  58.   return p_list 
  59. end
  60.  
  61. on getBehaviorDescription
  62.   return "Cause a sprite to snap to the registration point of the target sprite while being dragged.  " & RETURN & "PARAMETERS:" & RETURN & "ò Snap Distance - Enter the range in pixels within which snapping occurs." & RETURN & "ò Snap Target - Enter the channel number of the sprite to snap to." 
  63.   
  64. end